﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AJAXServiceProxyGeneration;

namespace AJAXCodeGenerator.Generator
{
    public partial class ScriptSharp : UserControl, IGeneratorControl
    {
        public ScriptSharp()
        {
            InitializeComponent();

            #if !Debug
            //Clear TextBox Default Data
            this.txtNamespace.Clear();
            this.txtWSDL.Clear();
            this.txtPocoNamespace.Clear();
            this.txtExcludeNames.Clear();

            #endif
        }
        #region Constants

        private const string URI = "uri";
        private const string NAMESPACE = "ns";
        private const string POCO_NAMESPACE = "poco";
        private const string EXCLUDES = "exc";

        #endregion

        #region IGeneratorControl Members

        public AJAXServiceProxyGeneration.IGenerator GetGenerator()
        {
            ScriptSharpGenerator serviceGenerator = new ScriptSharpGenerator(this.txtNamespace.Text, this.txtPocoNamespace.Text, this.txtWSDL.Text, this.txtExcludeNames.Text);
            return serviceGenerator;  
        }
        

        public GeneratorSettings GetSettings()
        {
            GeneratorSettings settings = new GeneratorSettings();
            settings.Settings = new GeneratorSetting[]
            {
                new GeneratorSetting(NAMESPACE, this.txtNamespace.Text),
                new GeneratorSetting(URI, this.txtWSDL.Text),
                new GeneratorSetting(POCO_NAMESPACE, this.txtPocoNamespace.Text),
                new GeneratorSetting(EXCLUDES, this.txtExcludeNames.Text)
            };
            return settings;
            
        }

        public void LoadSettings(GeneratorSettings generatorSettings)
        {
            foreach(GeneratorSetting setting in generatorSettings.Settings)
            {
                if( setting.Name.Equals(URI))
                {
                    this.txtWSDL.Text = setting.Value;
                }
                else if( setting.Name.Equals(NAMESPACE))
                {
                    this.txtNamespace.Text = setting.Value;
                }
                else if (setting.Name.Equals(POCO_NAMESPACE))
                {
                    this.txtPocoNamespace.Text = setting.Value;
                }
                else if (setting.Name.Equals(EXCLUDES))
                {
                    this.txtExcludeNames.Text = setting.Value;
                }
            }
            
        }

        #endregion
    }
}
